import httpx
from botoy import S
from botoy.decorators import ignore_botself, on_regexp,equal_content


def get_bdbk(word):
    resp=httpx.get(
        'https://baike.baidu.com/api/openapi/BaikeLemmaCardApi?appid=379020&bk_key={}'.format(word),
        timeout=10,
        )
    data=resp.json()
    return [data["abstract"],data["url"]]
    
@ignore_botself
@on_regexp(r"百度百科 (\S+)")

def receive_group_msg(ctx):
    try:
        data=get_bdbk(ctx._match.group(1))
        msg='词条:{0}\r\n释义:{1}\r\nurl:{2}'.format(ctx._match.group(1),data[0],data[1])
        S.text(msg)
    except:
        S.text('暂未收录此词条')
